import pandas as pd
from lightgbm import LGBMClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.preprocessing import minmax_scale
from sklearn.svm import SVC
from sklearn.tree import DecisionTreeClassifier
from xgboost import XGBClassifier


def read_total_data(DataFrame):
    feature = []
    label = []
    for row in range(len(DataFrame)):
        temp_feature = []
        for col in range(len(DataFrame.columns) - 1):
            temp_feature.append(DataFrame[DataFrame.columns[col]][row])
        feature.append(temp_feature)
        label.append(DataFrame[DataFrame.columns[len(DataFrame.columns) - 1]][row])
    return feature, label


# data = pd.read_csv("australian.dat", sep=" ", header=None)
# data = pd.read_csv("data_encoder_2.csv")
# data = pd.read_excel("default of credit card clients.xls")
# data = pd.read_csv("UKtomas.csv", header=None)
# data = pd.read_csv("PAKDD.csv")
data = pd.read_csv("2016leadingclub.csv")

total_feature, total_label = read_total_data(data)

# 归一化
total_feature_01 = minmax_scale(total_feature)

X_train, X_test, Y_train, Y_test = train_test_split(total_feature_01,
                                                    total_label,
                                                    train_size=0.7,
                                                    test_size=0.3,
                                                    random_state=0
                                                    )

# DNN = MLPClassifier(random_state=0).fit(X_train, Y_train)
DT = DecisionTreeClassifier(random_state=0).fit(X_train, Y_train)
# RF = RandomForestClassifier(random_state=0).fit(X_train, Y_train)
# LR = LogisticRegression(random_state=0).fit(X_train, Y_train)
# SVM = SVC(random_state=0).fit(X_train, Y_train)
# KNN = KNeighborsClassifier().fit(X_train, Y_train)
# xgb = XGBClassifier(random_state=0).fit(X_train, Y_train)
# lgb = LGBMClassifier(random_state=0).fit(X_train, Y_train)

Y_predict = DT.predict(X_test).tolist()

error_feature = []
error_label = []
index = 0
for i in Y_test:
    if i == Y_predict[index]:
        index += 1
    else:
        error_feature.append(X_test[index])
        error_label.append(Y_test[index])
        index += 1

# print(DT.score(error_feature, error_label))

error_sample = pd.DataFrame(error_feature)
error_sample = pd.concat([error_sample, pd.DataFrame(error_label)], axis=1, ignore_index=True, sort=False)

error_sample.to_csv("Lendingclub_DT_error.csv",
                    header=False,
                    index=False)
print(error_label)
print(error_sample)





















